<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-card>
        <el-tabs>
          <el-tab-pane label="登录账户设置">
            <el-form
              ref="userForm"
              :model="formData"
              :rules="rules"
              label-width="120px"
              style="margin-left: 120px; margin-top: 30px"
            >
              <el-form-item label="姓名:" prop="username">
                <el-input v-model="formData.username" style="width: 300px" />
              </el-form-item>
              <el-form-item label="密码:" prop="newpassword">
                <el-input
                  v-model="formData.newpassword"
                  style="width: 300px"
                  type="newpassword"
                />
              </el-form-item>
              <el-form-item>
                <el-button type="success" @click="saveUser">更新</el-button>
              </el-form-item>
            </el-form></el-tab-pane>
          <el-tab-pane label="个人详情">
            <userfrom />
          </el-tab-pane>
          <el-tab-pane label="岗位信息"><jobindo /> </el-tab-pane></el-tabs>
      </el-card>
    </div>
  </div>
</template>
<script>
import { getUserDetailById, saveUserDetailById } from '@/api/user'
import jobindo from './components/job-indo.vue'
import userfrom from './components/user-info.vue'
export default {
  components: { jobindo, userfrom },
  data() {
    return {
      userinfo: this.$route.params.id,
      formData: {
        username: '',
        newpassword: ''
      },
      rules: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' }
        ],
        password: [{ required: true, message: '请输入密码', trigger: 'blur' }]
      }
    }
  },
  created() {
    this.getUserInfo()
  },
  methods: {
    async getUserInfo() {
      this.formData = await getUserDetailById(this.userinfo)
    },
    async saveUser() {
      try {
        await this.$refs.userForm.validate()
        this.formData.password = this.formData.newpassword
        await saveUserDetailById(this.formData)
        this.$message('更新成功')
        this.$router.back()
      } catch (error) {
        console.log(error)
      }
    }
  }
}
</script>

<style>
</style>
